package com.dao.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.dao.AdminDAO;
import com.dao.BaseDao;
import com.entity.Admin;


@Repository
public class AdminDAOImpl extends BaseDao implements AdminDAO{

	@Override
	public int doAdd(Admin admin) {
		String sql="insert into admin"
				+ " (adminAccount,adminPwd)"
				+ " values"
				+ " (?,?)";
		Object[] params={admin.getAdminAccount(),admin.getAdminPwd()};
		return executeUpdate(sql, params);
	}

	@Override
	public List<Map<String, Object>> findAll() {
		String sql="select aId,adminAccount,adminPwd from admin";
		return executeQuery(sql, null);
	}

	@Override
	public Admin isByAdmin(String adminAccount, String adminPwd) {
		String sql="select aId,adminAccount,adminPwd"
				+ " from admins"
				+ " where adminAccount=? and adminPwd=?";
		Object[] params={adminAccount,adminPwd};
		List<Map<String,Object>> list=executeQuery(sql, params);
		if(list.size()>0){
			Map<String, Object> map=list.get(0);
			Admin admin=new Admin();
			admin.setaId((Integer)map.get("aId"));
			admin.setAdminAccount((String)map.get("adminAccount"));
			admin.setAdminPwd((String)map.get("adminPwd"));
			return admin;
		}
		return null;
	}



}
